<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>错误日志列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${ctx}/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="dateSelect" placeholder="-">
                </div>
                <a class="layui-btn search_btn" data-type="reload">搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="errorLogList" lay-filter="errorLogList"></table>
</form>
<!--操作-->
<script type="text/html" id="demoListBar">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="look">标记查看</a>
</script>

<script type="text/javascript" src="${ctx}/layui/layui.js"></script>
<script>
    layui.use(['form', 'layer', 'table', 'laytpl', 'laydate'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table,
            laydate = layui.laydate;


        //日期范围
        laydate.render({
            elem: '#dateSelect'
            ,range: true
        });

        //分页列表
        var tableIns = table.render({
            elem: '#errorLogList',
            url: '${ctx}/errorLog/page',
            cellMinWidth: 95,
            page: true,
            height: "full-125",
            loading: true,
            id: "errorLogListTable",
            request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                ,statusCode: 10200 //规定成功的状态码，默认：0
                ,msgName: 'message' //规定状态信息的字段名称，默认：msg
                ,countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'records' //规定数据列表的字段名称，默认：data
            },
            cols: [[
                {field: 'ip', title: 'ip', minWidth: 100, align: "center"},
                {field: 'className', title: '类名', minWidth: 100, align: "center"},
                {field: 'methodName', title: '方法名', minWidth: 100, align: "center"},
                {field: 'exceptionType', title: '错误类型', minWidth: 100, align: "center"},
                {field: 'exceptionMsg', title: '错误信息', minWidth: 100, align: "center"},
                {field: 'view', title: '是否查看', minWidth: 100, align: "center", templet:function (d) {
                    if (d.view == 0) {
                        return "<span style='color: red'>否</sapn>";
                    }
                    if (d.view == 1) {
                        return "<span style='color: green'>是</span>";
                    }
                }},
                {field: 'gmtCreate', title: '创建时间', minWidth: 100, align: "center"},
                {title: '操作', width: 360, templet: '#demoListBar', fixed: "right", align: "center"}
            ]]
        });

        //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
        $(".search_btn").on("click", function () {
            tableIns.reload({
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: { //设定异步数据接口的额外参数，任意设
                    dateSelect: $("#dateSelect").val()
                }
            })
        });

        //删除
        function toLook (errorLogId) {
            $.ajax({
                url: '${ctx}/errorLog/updateIsView',
                data: {errorLogId:errorLogId},
                method: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code == 10200) {
                        layer.msg("操作成功", {icon: 6});
                        tableIns.reload();
                    }else {
                        layer.msg(res.message, {icon: 5});
                    }
                },
                error: function () {
                    layer.msg("系统繁忙,请稍后再试!", {icon: 5});
                }
            });
        }

        //列表操作
        table.on('tool(errorLogList)', function (obj) {
            var layEvent = obj.event,
                //当前行数据
                data = obj.data;

            if (layEvent === 'look') {
                toLook(data.id)
            }
        });
    })
</script>
</body>
</html>
